home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / ebksrc.zip / PCPUT2.CPP < prev    next >
C/C++ Source or Header  |  1991-08-10  |  2KB  |  100 lines

  1. /*
  2.  
  3.     pcput2.cpp
  4.     7-30-91
  5.     Write two color text strings
  6.  
  7.     Copyright 1991
  8.     John W. Small
  9.     All rights reserved
  10.     Use freely but acknowledge authorship and copyright.
  11.  
  12.     PSW / Power SoftWare
  13.     P.O. Box 10072
  14.     McLean, Virginia 22102 8072 USA
  15.  
  16.     John Small
  17.     Voice: (703) 759-3838
  18.     CIS: 73757,2233
  19.  
  20. */
  21.  
  22. #include <pcput2.hpp>
  23.  
  24. int ScrLnBuf::buf[MAX_SCR_LN_BUF];
  25.  
  26. void ScrLnBuf::set(int normattr, int highattr,
  27.     unsigned pgWidth, unsigned startColumn, int clreol,
  28.     char lineTermChar, char attrToggleChar,
  29.     unsigned tabSpacing)
  30. {
  31.     this->normattr        =  normattr;
  32.     this->highattr        =  highattr;
  33.     if (pgWidth > MAX_SCR_LN_BUF)
  34.         this->pgWidth = MAX_SCR_LN_BUF;
  35.     else
  36.         this->pgWidth = pgWidth;
  37.     this->startColumn     =  startColumn;
  38.     this->clreol          =  clreol;
  39.     this->lineTermChar    =  lineTermChar;
  40.     this->tabSpacing      =  tabSpacing;
  41.     this->attrToggleChar  =  attrToggleChar;
  42.     eolColumn             =  1;
  43.     lidx                  =  0;
  44. }
  45.  
  46. int ScrLnBuf::writebuf(const char *line)
  47. {
  48.     int toggle = 0;
  49.     int attr = (normattr << 8);
  50.     int bidx = 0;
  51.     eolColumn = 1;
  52.     if (line)  {
  53.         for (lidx = 0; bidx < pgWidth &&
  54.         line[lidx] && line[lidx] != lineTermChar;
  55.         lidx++)
  56.         if (line[lidx] == attrToggleChar)
  57.             if (line[lidx+1] == attrToggleChar)  {
  58.                 lidx++;
  59.                 if (eolColumn++ >= startColumn)
  60.                     buf[bidx++] = attr |
  61.                     (unsigned char)
  62.                     attrToggleChar;
  63.             }
  64.             else
  65.                 if (++toggle % 2)
  66.                     attr = (highattr << 8);
  67.                 else
  68.                     attr = (normattr << 8);
  69.         else if (line[lidx] == '\t')
  70.             do {
  71.                 if (eolColumn >= startColumn)
  72.                     buf[bidx++] = attr |
  73.                     (unsigned char) ' ';
  74.             } while (eolColumn++ % tabSpacing);
  75.         else  if (eolColumn++ >= startColumn)
  76.                 buf[bidx++] = attr |
  77.                 (unsigned char) line[lidx];
  78.         for (int i = lidx; line[i]
  79.             && line[i] != lineTermChar; i++)
  80.         if (line[i] == attrToggleChar)  {
  81.             if (line[i+1] == attrToggleChar)  {
  82.                 i++;
  83.                 eolColumn++;
  84.             }
  85.         }
  86.         else if (line[i] == '\t')
  87.             while (eolColumn++ % tabSpacing)
  88.                 /* null stmt */;
  89.         else
  90.             eolColumn++;
  91.     }
  92.     if (bidx < pgWidth && clreol)  {
  93.         attr |= (unsigned char) ' ';
  94.         while (bidx < pgWidth)
  95.             buf[bidx++] = attr;
  96.     }
  97.     return bidx;
  98. }
  99.  
  100.